/*
 * CUCA_engine.h
 *
 *  Created on: 04/05/2012
 *      Author: utnso
 */

#ifndef CUCA_ENGINE_H_
#define CUCA_ENGINE_H_

// INCLUDES
#include <stdint.h>
#include <pthread.h>
#include <stdbool.h>
#include <memcached/engine.h>
#include <memcached/util.h>
#include <memcached/visibility.h>
#include <libmemcached/memcached.h>
#include <signal.h>
#include "libArchivoConfiguracion.h"
#include "libCache.h"

//TIPOS
typedef struct CUCA_engine_t{
	ENGINE_HANDLE_V1 engine;
}CUCA_engine_t;

typedef struct CUCA_item_t{
	char* key;
	size_t key_length;
	char* data;
	size_t data_length;
}CUCA_item_t;

/* FUNCIONES DUMMY */
ENGINE_ERROR_CODE CUCA_get_stats(ENGINE_HANDLE* , const void* cookie, const char* stat_key, int nkey, ADD_STAT add_stat);
void CUCA_reset_stats(ENGINE_HANDLE* , const void *cookie);
ENGINE_ERROR_CODE CUCA_unknown_command(ENGINE_HANDLE* , const void* cookie, protocol_binary_request_header *request, ADD_RESPONSE response);
void CUCA_item_set_cas(ENGINE_HANDLE *, const void *cookie, item* item, uint64_t val);

//FUNCIONES
MEMCACHED_PUBLIC_API ENGINE_ERROR_CODE create_instance(uint64_t interface, GET_SERVER_API get_server_api, ENGINE_HANDLE **handle);

ENGINE_ERROR_CODE CUCA_initialize(ENGINE_HANDLE* handle, const char* config_str);

void CUCA_destroy(ENGINE_HANDLE* handle, const bool force);

const engine_info* CUCA_get_info(ENGINE_HANDLE* );

ENGINE_ERROR_CODE CUCA_allocate(ENGINE_HANDLE *handler, const void* cookie, item **item, const void* key, const size_t nkey, const size_t nbytes, const int flags, const rel_time_t exptime);

void CUCA_item_release(ENGINE_HANDLE *handler, const void *cookie, item* item);

bool CUCA_get_item_info(ENGINE_HANDLE *handler, const void *cookie, const item* item, item_info *item_info);

ENGINE_ERROR_CODE CUCA_get(ENGINE_HANDLE *handle, const void* cookie, item** item, const void* key, const int32_t key_length, uint16_t vbucket);

ENGINE_ERROR_CODE CUCA_store(ENGINE_HANDLE *handle, const void *cookie, item* item, uint64_t *cas, ENGINE_STORE_OPERATION operation, uint16_t vbucket);

ENGINE_ERROR_CODE CUCA_remove(ENGINE_HANDLE* handle, const void* cookie, const void* key, const size_t key_length, uint64_t cas, uint16_t vbucket);

ENGINE_ERROR_CODE CUCA_flush(ENGINE_HANDLE* handle, const void* cookie, time_t expiration);

void DumpearCache(int32_t signal);

#endif /* CUCA_ENGINE_H_ */
